import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path' // 来自于 @types/node 这个包

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import DefineOptions from 'unplugin-vue-define-options/vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    DefineOptions()
  ],
  server: {
    // 启动成功后自动打开浏览器
    open: true,
    // 允许通过 ip 地址访问
    host: '0.0.0.0',
    // 配置请求代理
    proxy: {
      '/v3': {
        target: 'http://localhost:3030', // API服务地址
        changeOrigin: true // 开启跨域
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve('./src') // @代替src
    }
  },
  css: {
    preprocessorOptions: {
      // 全局样式引入
      scss: {
        additionalData: '@import "./src/assets/style/variables.scss";',
        javascriptEnabled: true
      }
    }
  }
})
